// constants/deviceParameters.ts

// 定义设备参数的类型接口
export interface DeviceParam {
  id: string;
  label: string;
  type: 'switch' | 'button' | 'stepper' | 'readonly'; // 新增 readonly 类型用于只读字段
  initialValue: any; // 初始值类型不固定，可以是 boolean, string, number
  options?: string[]; // 按钮类型需要
  min?: number; // stepper 类型需要
  max?: number; // stepper 类型需要
  step?: number; // stepper 类型需要
}

// 定义设备类型枚举（完整版）
export enum DEVICE_TYPES {
  AC = '空调',
  LIGHT = '灯',
  CAMERA = '摄像头',
  DOOR_LOCK = '智能门锁',
  CATEYE = '猫眼',
  AIR_PURIFIER = '空气净化器',
  HUMIDIFIER = '加湿器',
  CURTAIN = '窗帘',
  WASHING_MACHINE = '洗衣机',
  VACUUM_ROBOT = '扫地机器人',
  REFRIGERATOR = '冰箱',
  DISHWASHER = '洗碗机',
  WATER_HEATER = '热水器',
  EXHAUST_FAN = '排气扇',
  SMART_TV = '电视',
  SMART_SPEAKER = '智能音箱',
  TEMP_HUMIDITY_SENSOR = '温湿度计',
  MOTION_SENSOR = '人体传感器',
  SMOKE_CO_ALARM = '烟雾报警器',
}

// 英文设备类型到中文设备类型的映射
export const deviceTypeEnToZhMap: Record<string, string> = {
  smart_lock_with_cat_eye: '智能门锁',
  camera: '摄像头',
  light: '灯',
  air_conditioner: '空调',
  air_purifier: '空气净化器',
  humidifier: '加湿器',
  curtain: '窗帘',
  washing_machine: '洗衣机',
  vacuum_robot: '扫地机器人',
  refrigerator: '冰箱',
  dishwasher: '洗碗机',
  water_heater: '热水器',
  exhaust_fan: '排气扇',
  smart_tv: '电视',
  smart_speaker: '智能音箱',
  temp_humidity_sensor: '温湿度计',
  motion_sensor: '人体传感器',
  smoke_co_alarm: '烟雾报警器',
};

export const optionLabels: Record<string, string> = {
  // 空调模式
  cool: '制冷',
  heat: '制热',
  dry: '除湿',
  fan: '送风',
  // 风速
  auto: '自动',
  low: '低速',
  medium: '中速',
  high: '高速',
  // 风向
  fixed: '固定',
  vertical: '上下摆风',
  horizontal: '左右摆风',
  swing: '自动摆风',
  // 洗衣机
  quick: '快洗/速热',
  normal: '标准',
  bulky: '大件',
  // 扫地机
  whole: '全屋',
  spot: '定点',
  edge: '边角',
  // 冰箱
  energy_saving: '节能',
  quick_cool: '速冷',
  holiday: '假日',
  // 电视输入源
  hdmi: 'HDMI',
  usb: 'USB',
  cast: '投屏',
  // 洗碗机
  strong: '强力',
  eco: '节能',
  // 热水器
  constant: '恒温',
  // quick: '速热',
  // 空气净化器
  sleep: '睡眠',
  turbo: '强力',
  // 加湿器
  // 其它可继续补充...
  standby: '待机',
  stopped: '已停止',
  alarm: '报警',
  normal_status: '正常',
  // 其它如有英文选项可继续补充
};

// 设备参数配置，现在每个值都是 DeviceParam 数组
export const deviceParameters: Record<DEVICE_TYPES, DeviceParam[]> = {
  [DEVICE_TYPES.AC]: [
    {
      id: 'is_on',
      label: '开关控制',
      type: 'switch',
      initialValue: false,
    },
    {
      id: 'mode',
      label: '模式调节',
      type: 'button',
      options: ['cool', 'heat', 'dry', 'fan'],
      initialValue: 'cool',
    },
    {
      id: 'target_temp',
      label: '温度设定',
      type: 'stepper',
      min: 16,
      max: 30,
      step: 1,
      initialValue: 24,
    },
    {
      id: 'fan_speed',
      label: '风速',
      type: 'button',
      options: ['auto', 'low', 'medium', 'high'],
      initialValue: 'auto',
    },
    {
      id: 'swing_mode',
      label: '风向',
      type: 'button',
      options: ['fixed', 'vertical', 'horizontal', 'swing'],
      initialValue: 'vertical',
    },
  ],
  [DEVICE_TYPES.LIGHT]: [
    {
      id: 'is_on',
      label: '开关控制',
      type: 'switch',
      initialValue: false,
    },
    {
      id: 'brightness',
      label: '亮度',
      type: 'stepper',
      min: 0,
      max: 100,
      step: 5,
      initialValue: 50,
    },
    {
      id: 'color_temp',
      label: '色温',
      type: 'stepper',
      min: 2000,
      max: 6500,
      step: 500,
      initialValue: '4000',
    },
  ],
  [DEVICE_TYPES.CAMERA]: [
    {
      id: 'is_on',
      label: '实时监控',
      type: 'switch',
      initialValue: true,
    },
    {
      id: 'motion_alert',
      label: '移动侦测报警',
      type: 'switch',
      initialValue: false,
    },
  ],
  [DEVICE_TYPES.DOOR_LOCK]: [
    {
      id: 'lock_state',
      label: '开锁/上锁',
      type: 'switch',
      initialValue: true,
    },
    {
      id: 'access_log',
      label: '开门日志',
      type: 'readonly',
      initialValue: '暂无记录',
    },
    {
      id: 'cat_eye_video',
      label: '视频联动猫眼',
      type: 'switch',
      initialValue: false,
    },
  ],
  [DEVICE_TYPES.AIR_PURIFIER]: [
    {
      id: 'is_on',
      label: '开关控制',
      type: 'switch',
      initialValue: false,
    },
    {
      id: 'mode',
      label: '模式调节',
      type: 'button',
      options: ['auto', 'sleep', 'turbo'],
      initialValue: 'auto',
    },
    {
      id: 'fan_speed',
      label: '风速控制',
      type: 'button',
      options: ['low', 'medium', 'high', 'auto'],
      initialValue: 'auto',
    },
    {
      id: 'pm25_value',
      label: 'PM2.5值',
      type: 'readonly',
      initialValue: 35.5,
    },
  ],
  [DEVICE_TYPES.HUMIDIFIER]: [
    {
      id: 'is_on',
      label: '开关控制',
      type: 'switch',
      initialValue: false,
    },
    {
      id: 'mist_level',
      label: '挡位调节',
      type: 'button',
      options: ['low', 'medium', 'high'],
      initialValue: 'medium',
    },
    {
      id: 'water_level_low',
      label: '缺水警告',
      type: 'readonly',
      initialValue: false,
    },
  ],
  [DEVICE_TYPES.CURTAIN]: [
    {
      id: 'percent',
      label: '开合比例',
      type: 'stepper',
      min: 0,
      max: 100,
      step: 5,
      initialValue: 50,
    },
  ],
  [DEVICE_TYPES.WASHING_MACHINE]: [
    {
      id: 'is_power_on',
      label: '开关',
      type: 'switch',
      initialValue: false,
    },
    {
      id: 'wash_program',
      label: '洗衣程序',
      type: 'button',
      options: ['quick', 'normal', 'bulky'],
      initialValue: 'normal',
    },
    {
      id: 'remaining_time_min',
      label: '当前进度',
      type: 'readonly',
      initialValue: 0,
    },
  ],
  [DEVICE_TYPES.VACUUM_ROBOT]: [
    {
      id: 'status',
      label: '工作状态',
      type: 'readonly',
      initialValue: 'standby',
    },
    {
      id: 'cleaning_mode',
      label: '清扫模式',
      type: 'button',
      options: ['whole', 'spot', 'edge'],
      initialValue: 'whole',
    },
    {
      id: 'battery_level',
      label: '电量',
      type: 'readonly',
      initialValue: 100,
    },
  ],
  [DEVICE_TYPES.REFRIGERATOR]: [
    {
      id: 'fridge_temp',
      label: '冷藏温度',
      type: 'readonly',
      initialValue: 4.5,
    },
    {
      id: 'freezer_temp',
      label: '冷冻温度',
      type: 'readonly',
      initialValue: -18.0,
    },
    {
      id: 'mode',
      label: '模式切换',
      type: 'button',
      options: ['energy_saving', 'quick_cool', 'holiday'],
      initialValue: 'energy_saving',
    },
  ],
  [DEVICE_TYPES.DISHWASHER]: [
    {
      id: 'is_running',
      label: '运行状态',
      type: 'switch',
      initialValue: false,
    },
    {
      id: 'wash_mode',
      label: '清洗程序',
      type: 'button',
      options: ['strong', 'quick', 'eco'],
      initialValue: 'eco',
    },
  ],
  [DEVICE_TYPES.WATER_HEATER]: [
    {
      id: 'is_on',
      label: '开关控制',
      type: 'switch',
      initialValue: false,
    },
    {
      id: 'target_temp',
      label: '温度设定',
      type: 'stepper',
      min: 30,
      max: 75,
      step: 1,
      initialValue: 50,
    },
    {
      id: 'mode',
      label: '模式调节',
      type: 'button',
      options: ['constant', 'eco', 'quick'],
      initialValue: 'eco',
    },
  ],
  [DEVICE_TYPES.EXHAUST_FAN]: [
    {
      id: 'is_on',
      label: '开关控制',
      type: 'switch',
      initialValue: false,
    },
    {
      id: 'timer_minutes',
      label: '定时运行',
      type: 'stepper',
      min: 0,
      max: 120,
      step: 5,
      initialValue: 0,
    },
  ],
  [DEVICE_TYPES.SMART_TV]: [
    {
      id: 'is_on',
      label: '开关控制',
      type: 'switch',
      initialValue: false,
    },
    {
      id: 'input_source',
      label: '输入源',
      type: 'button',
      options: ['hdmi', 'usb', 'cast'],
      initialValue: 'hdmi',
    },
    {
      id: 'volume',
      label: '音量',
      type: 'stepper',
      min: 0,
      max: 100,
      step: 5,
      initialValue: 50,
    },
  ],
  [DEVICE_TYPES.SMART_SPEAKER]: [
    {
      id: 'volume',
      label: '音量控制',
      type: 'stepper',
      min: 0,
      max: 100,
      step: 5,
      initialValue: 50,
    },
    {
      id: 'playback_status',
      label: '播放状态',
      type: 'readonly',
      initialValue: 'stopped',
    },
  ],
  [DEVICE_TYPES.TEMP_HUMIDITY_SENSOR]: [
    {
      id: 'temperature_c',
      label: '当前温度',
      type: 'readonly',
      initialValue: 25.0,
    },
    {
      id: 'humidity_percent',
      label: '当前湿度',
      type: 'readonly',
      initialValue: 50.0,
    },
  ],
  [DEVICE_TYPES.MOTION_SENSOR]: [
    {
      id: 'has_motion',
      label: '实时监控',
      type: 'readonly',
      initialValue: false,
    },
  ],
  [DEVICE_TYPES.SMOKE_CO_ALARM]: [
    {
      id: 'smoke_ppm',
      label: '烟雾浓度',
      type: 'readonly',
      initialValue: 0.0,
    },
    {
      id: 'co_ppm',
      label: 'CO 浓度',
      type: 'readonly',
      initialValue: 0.0,
    },
    {
      id: 'alarm_status',
      label: '报警状态',
      type: 'readonly',
      initialValue: 'normal',
    },
  ],
  [DEVICE_TYPES.CATEYE]: [
    {
      id: 'is_on',
      label: '开关控制',
      type: 'switch',
      initialValue: false,
    },
  ]
};